﻿using MediatR;
using Sowrk03_28.Repository;
using Swork03_28.Api.Application.Commands.FarmedCommand;
using Swork03_28.Domain.TraceableInfos;

namespace Swork03_28.Api.Application.CommandHandlers.FarmedHandler
{
    public class HealthCreateCommandHandler : IRequestHandler<HealthCreateCommand, int>
    {
        private readonly IRepository<Vaccine> _viccine;

        public HealthCreateCommandHandler(IRepository<Vaccine> viccine)
        {
            _viccine = viccine;
        }

        public async Task<int> Handle(HealthCreateCommand request, CancellationToken cancellationToken)
        {
            var count = 0;
            count += await _viccine.CreateAsync(new Vaccine()
            {
                Id = request.Id,
                BatchId = request.BatchId,
                FeedingDays = request.FeedingDays,
                HealthCareMethod = request.HealthCareMethod,
                HealthCareMode = request.HealthCareMode,
            });
            return count;
        }

        public class HealthUpdateCommandHandler : IRequestHandler<HealthUpdateCommand, int>
        {
            private readonly IRepository<Vaccine> _viccine;

            public HealthUpdateCommandHandler(IRepository<Vaccine> viccine)
            {
                _viccine = viccine;
            }

            public async Task<int> Handle(HealthUpdateCommand request, CancellationToken cancellationToken)
            {
                var count = 0;
                count += await _viccine.UpdateAsync(new Vaccine()
                {
                    Id = request.Id,
                    BatchId = request.BatchId,
                    FeedingDays = request.FeedingDays,
                    HealthCareMethod = request.HealthCareMethod,
                    HealthCareMode = request.HealthCareMode,
                });
                return count;
            }
        }

        public class HealthDeleteCommandHandler : IRequestHandler<HealthDeleteCommand, int>
        {
            private readonly IRepository<Vaccine> _vacine;

            public HealthDeleteCommandHandler(IRepository<Vaccine> vacine)
            {
                _vacine = vacine;
            }

            public async Task<int> Handle(HealthDeleteCommand request, CancellationToken cancellationToken)
            {
                var del = await _vacine.GetAsync(request.Id);
                return await _vacine.DeleteAsync(del);
            }
        }
    }
}
